<template>
  <Layout class="p-5 bg-white">
    <Form
      :label-width="100"
      :rules="ruleValidate"
      ref="equipment"
      :model="equipment"
    >
      <Row>
        <Col span="8">
          <FormItem class="w-75" label="设备编号" prop="id">
            <Input
              v-model="equipment.id"
              placeholder="请输入设备编号"
            ></Input>
          </FormItem>
		  <FormItem class="w-75" label="设备名称" prop="equipmentName">
		    <Input
		      v-model="equipment.equipmentName"
		      placeholder="请输入设备名称"
		    ></Input>
		  </FormItem>
		  <FormItem class="w-75" label="设备信息">
		    <Input
			  type="textarea" 
			  :autosize="{minRows: 2,maxRows: 5}"
		      v-model="equipment.equipmentInfo"
		      placeholder="请输入设备信息"
		    ></Input>
		  </FormItem>
          <FormItem class="text-right">
            <Button v-preventReClick @click="submit" type="primary"
              >提交</Button
            >
            <Button @click="cancel" class="ml-2">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
      ruleValidate: {
        id: [
          {
            required: true,
            message: 'id不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
        equipmentName: [
          {
            required: true,
            message: '名称不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
      },
      equipment:{
		  id:'',
		  equipmentName:'',
		  statu:1,
		  equipmentInfo:'',
	  }
      
    }
  },
  created: function() {
  },
  methods: {
    submit: function() {
      if (this.$data.equipment.id.trim().length === 0) {
        this.message.error('设备编号必须输入')
        return
      }
	  if (this.$data.equipment.id.indexOf(' ') > -1) {
	    this.message.error('设备编号中不能有空格')
	    return
	  }
      if (this.$data.equipment.equipmentName.trim().length === 0) {
        this.message.error('设备名必须输入')
        return
      }
	  if (this.$data.equipment.equipmentName.indexOf(' ') > -1) {
	    this.message.error('名称中不能有空格')
	    return
	  }
      let self = this

      let param = {
        id : this.$data.equipment.id,
		equipmentName: this.$data.equipment.equipmentName,
		statu: this.$data.equipment.statu,
		equipmentInfo: this.$data.equipment.equipmentInfo
      }
      this.http
        .post({
          url: '/equipment',
          param: param,
        })
        .then((data) => {
          self.message.info('新增成功')
          this.$tabs.close({ to: '/machine' })
        })
    },
    cancel: function() {
      this.$tabs.close({ to: '/machine' })
    },
  },
}
</script>

<style></style>
